/*join.c*/  
#include <pthread.h>  
#include <stdio.h>  

void *t1_exe(void *arg) {  
    int i;  
    printf("The first thread: \n");  
    for (i = 1; i < 6; i++)  
        printf("%d\n", i);  
    fflush(stdout);  
    return NULL;  
}  

void *t2_exe(void *arg) {  
    int i;  
    printf("The second thread: \n");  
    for (i = 6; i < 11; i++)  
        printf("%d\n", i);  
    return NULL;  
}  

int main() {  
    pthread_t pid1, pid2;  
    int error1, error2;  
    error1 = pthread_create(&pid1, NULL, t1_exe, NULL);  
    error2 = pthread_create(&pid2, NULL, t2_exe, NULL);  
    if (error1 != 0 || error2 != 0) {  
        printf("pthread_create failed ");  
        return -1;  
    }  
    pthread_join(pid1, NULL);  
    pthread_join(pid2, NULL);  
    return 0;  
}  
